﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codeplus.Library.Recaptcha
{
    public class RecaptchaStatusCode
    {
        public const string InvalidSitePrivateKey = "invalid-site-private-key";
        public const string InvalidRequestCookie = "invalid-request-cookie";
        public const string IncorrectCaptchSol = "incorrect-captcha-sol";
        public const string RecaptchaNotReachable = "recaptcha-not-reachable";

        /// <summary>
        /// 
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static bool IsSuccessful(string response)
        {
            return response.StartsWith("true");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static string GetErrorCode(string response)
        {
            if (response.StartsWith("false"))
            {
                var parts = response.Split("\n".ToArray());
                return parts[1];
            }
            return null;
        }
    }
}
